const app = getApp()
const api = require('../../../api/index.js')
const util = require("../../../utils/util.js")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    "brandList": [],
    "wordindex": [],
    "toView": '#',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      imgSrc: api.imgPathUrl
    })
    this.setData({
      id: options.id
    })
    this.channel()
  },
  channel: function () {
    let data = {
      c_id: this.data.id,
      longitude: wx.getStorageSync('key').longitude,
      latitude: wx.getStorageSync('key').latitude
    }
    api.channel(data, (res) => {

      this.setData({
        channelData: res.data.result
      })
      let channelDataS = res.data.result.classify

      var obj = this.data.id
      var index = channelDataS.map(item => item.id).indexOf(obj)
      channelDataS.splice(0, 0, channelDataS[index]);
       channelDataS.splice(index+1, 1);
      // console.log(channelDataS)
      let dataC = `channelData.classify`
      this.setData({
        [dataC]: channelDataS
      })
    })
  },
  sectionData:function(e){
    let id = e.currentTarget.dataset.id
    // console.log(id)
    let data = {
      c_id: id,
      longitude: wx.getStorageSync('key').longitude,
      latitude: wx.getStorageSync('key').latitude
    }
    api.channel(data, (res) => {
      console.log(channel)
      this.setData({
        channelData:res.data.result
      })
    })
  },
  allData:function(e){
    // console.log()
    let id = e.currentTarget.dataset.id
    let data = {
      cate_id:id
    }
    wx.navigateTo({
      url: `/pages/indexs/channelAll/channelAll?id=${id}`,
    })
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})